package com.codemes.happylist.modules.login;

import com.codemes.happylist.model.UserLogin;
import de.felixroske.jfxsupport.FXMLController;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * @author nscoffee
 */
@Slf4j
@FXMLController
public class UserLoginController  implements Initializable {

    @FXML
    private Button loginBtn;
    @FXML
    private TextField txt_userName;
    @FXML
    private TextField txt_password;

    private UserLogin userLogin = new UserLogin();

    @Autowired
    UserLoginService userLoginService;



    /**
     * 点击登录
     * @param event
     */
    public void doLogin(ActionEvent event){
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setContentText("test,测试提示内容较多的情况，是否可以显示完整，测试提示内容较多的情况，是否可以显示完整，测试提示内容较多的情况，是否可以显示完整，测试提示内容较多的情况，是否可以显示完整");
        alert.setResizable(true);
        alert.showAndWait();
        log.info("event={}",event);
        String userName = txt_userName.getText();
        String password = txt_password.getText();
        log.info("name={} pwd={}",userName,password);

        log.info("loginInfo={}",userLogin);

        userLoginService.doLogin(userLogin);
    }

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        txt_userName.textProperty().bindBidirectional(userLogin.getUsername());
        txt_password.textProperty().bindBidirectional(userLogin.getPassword());
    }
}
